About the Demo

This example shows how to use Eco with ASP.Net. It is intentionally "simple" in that it concentrates on Eco Aspects only, and not on general ASP.NET aspects. It also shows a simple example of implementing a WebService.

Setup Information

No setup should be needed for running this demo under Cassini.

If you are planning to run this ASP demo under IIS it is necessary to create a Virtual Directory with IIS. The easiest way of doing this is as follows:
  1. From the Projectmenu, select Options
  2. Select to ASP.Net
  3. Click on the Server Optionsbutton
  4. Change the Alias Name (e.g. add a '1' at the end of the Server Name)
  5. hit OKto close the Server Options dialog, and OKto close the Project Options dialog. This will force the Project manager to create a new ASP directory with the new Project Name

In addition you need to change the BdpConnection1.DatabaseName to an absolute path including the machine name. Something like "localhost:c:\program files\Borland\BDS\3.0\Demos\Delphi.Net\ECO\ASP\SimpleWebDemo\Database\SimpleEcoWebDemo.gdb"

Running the Demo

This section should list the steps necessary for the user to get the demo loading into the IDE and running.
  1. Press F9 in the IDE

The description of the steps below should giva a good idea of what to look for in the code, and when using the application.

You can test the webservices in IE by browsning to OrderServices.ASPX, and observe the effects in another Browser window by pressing F5.

Steps

This is a list of most of the steps needed for creating the Demo from scratch.

Setup

  1. File|NewDelphi for .Net Projects|Eco ASP.Net Web application
  2. Compile, Close and reopen project (This ensures that the PersistenceMapperProvder.EcoSpaceType, PersistenceMapperSharer1.MapperProvider and rhRoot.EcoSpaceType will not loose their values). 
  3. Place and connect Persistence components on EcoPersistenceMapperProvider
  4. Set the SyncActive property on the PersistenceMapper used to true.
  5. Draw Model. If using the same model, please note that since Order is a reserved word in SQL you need to set two tagged values. Order.Table Name="OrderTable" and OrderItem.Order.Coumn Name="OrderColumn".
  6. Create Database

Creating the Main form

  1. Place a button Create Test Data, and add Code to Create Test Data. Note that all events that change things will normally end with UpdateDataBase(); DataBind().
  2. Place and ExpressionHandle, and set RootHandle=rhroot, Expression="Order.allInstaces", AddExternalId=true. 
  3. Place a Datagrid on the form, and set its DataSource to the Expression handle created in step 8, and the DataKeyField="ExternalId"; 
  4. Open the Editor for the Columns property. Uncheck "Create columns...", and select all columns except ExternalId.

You can now test run the application.

Making the grid Editable

There is some code in the template that can be used for making the grid editable. It can also be mined for "how to do things in code".

  1. Connect the events CancelCommand, DeleteCommand, EditCommand and UpdateCommand to the method with the corresponding name.
  2. Open the Columns editor again from the Button commands select first "Edit, Update, Cancel" and then Delete.

Run the application again, and try out the options.

Creating and using the detail form

There is some code in the template that can be used for making the grid editable. It can also be mined for "how to do things in code".

  1. Add a new Eco webform
  2. Set rhRoot.EcoSpacetype, and Set RhRoot.StaticValueType to "Order". This indactes that th referenceHandle will always point to an Order, and is needed to enable designtime OCL support. Note that the code in Page_Load will setup rhRoot if the URL contains an external ID.
  3. Add three textboxes for the three attributes of Order, adn connecdt them to rhRoot[0].Customer etc using the editor on the Data
  4. Add an expressionhandle, RootHandle=rhroot, Expression="self.OrderItem", AddExternalId=true. 
  5. Add a grid, and connect it up the same way as before.
  6. Add a button with code for updating changes to the attributes. The example contains three ways of doing this, with comments.
  7. If you want to show off, add an ExpressionHandle for the OrderTotal, and Connect a Label to it.
  8. Now go back to the main from, and add a button for creating a new Order and showing it the the deatil form. Look at the code in the Example.

Editing in the detail form

Finally add code in the main form to open the details form for a given row in the grid:

  1. Open the Colums editor on the grid on the main form
  2. Add a Hyperrlink Column
  3. Set Text=Detail, URL Field=ExternalId, URL Format String= OrderForm.aspx?RootId={0}

Enjoy!

Troubleshooting

The file web.config contains lines of the form: 

<add assembly="Borland.Eco.Handles, Version=x.x.x.x, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b"/>
 

If you get an error message at runtime indicating that the compiler can't find one of these assemblies, you may need to update the version number. The correct version number can be found by double clicking on the DLL in the project manager.

These lines are only needed if the assemblies are to be found in the GAC. If the assembiles are deployed with the application, there lines can be removed from Web.config.